package com.kt.kvw.util;

import java.lang.reflect.Array;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-07-12
 * Time: 16:33
 */
public final class MapUtils {

    public static <K, V> Map<K, V> of(K key, V value) {
        if (key == null || value == null) {
            return Collections.EMPTY_MAP;
        }
        Map<K, V> map = new HashMap<>(1);
        map.put(key, value);
        return map;
    }

    public static <K, V> Map<K, V> of(K[] keys, V[] values) {
        if (keys == null || keys.length == 0 || values == null || values.length == 0) {
            return Collections.EMPTY_MAP;
        }
        int length = Math.min(keys.length, values.length);
        Map<K, V> map = new HashMap<>(length);
        for (int i = 0; i < length; i++) {
            map.put(keys[i], values[i]);
        }
        return map;
    }
}
